
/**
 * 详情对话框
 */
var OrderInfoDlg = {
    data: {
        orderNo: "",
        playerId: "",
        totalPrice: "",
        payPrice: "",
        payScore: "",
        payScorePrice: "",
        shipFee: "",
        receiverName: "",
        receiverPhone: "",
        receiverAddr: "",
        orderStatus: "",
        payStatus: "",
        payType: "",
        shipCompany: "",
        shipNo: "",
        remark: "",
        agentId: "",
        deptid: "",
        payTime: "",
        shipTime: "",
        receiveTime: "",
        handlePerson: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    },


    tableId: "orderGoodsTable",


};

layui.use(['form', 'admin', 'ax','laydate','table'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var table = layui.table;


    /**
     * 初始化表格的列
     */
    OrderInfoDlg.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true,hide:'true', title: 'id'},
            {field: 'goodsName'
                , sort: true, align:'center', title: '商品名'
            },
           /* {field: 'skuPic', sort: true, align:'center', title: '规格图片',
               /!* templet: "#imgTpl"*!/
            },*/
            {field: 'skuCount', sort: true, align:'center', title: '数量'},
            {field: 'skuName', sort: true,  align:'center',title: '规格'},
            {field: 'skuPrice', sort: true, align:'center', title: '商品价格'},
            {field: 'skuTotalPrice', sort: true, align:'center', title: '商品总价格'},
            {align: 'center',hide: true, toolbar: '#tableBar', title: '操作'}
        ]];
    };

    //让当前iframe弹层高度适应
    //admin.iframeAuto();

    /**
     * 发货与未发货状态下的不同显示效果
     */
    OrderInfoDlg.shipChange=function(data){
        var shipBox = $("#shipBox");
        var shipBtn = $("#shipBtn");
        var b = data.orderStatus==30; //如果待发货
        shipBox.find("input").attr("disabled","disabled")

    };

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/order/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('orderForm', result.data);
    OrderInfoDlg.shipChange(result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/order/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set("orderStatus",$("#orderStatus").val())
        ajax.set(data.field);
        ajax.start();
    });

    //快递表单提交事件
    form.on('submit(shipSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/order/ship", function (data) {
            Feng.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });


    laydate.render({
        elem: '#shipTime',
        type:'datetime',
    });


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + OrderInfoDlg.tableId,
        url: Feng.ctxPath + '/order/goodsList?orderId='+$("#id").val(),
        page: false,

        cellMinWidth: 100,
        cols: OrderInfoDlg.initColumn()
    });


    layer.photos({
        photos: '#layer-photos'
        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
});